#CC=/opt/buildroot-gcc1030-glibc232_kernel5_4/usr/bin/arm-buildroot-linux-gnueabi-gcc
PAHO_DIR = paho-mqtt-c
PAHO_BUILD = $(PAHO_DIR)/build
PAHO_LIB = $(PAHO_BUILD)/src/libpaho-mqtt3a.a
CC ?= gcc
all: mqtt_client
#cc -c -I. -DOSX *.c
$(PAHO_LIB):
	mkdir -p $(PAHO_DIR)/build/src
	cd $(PAHO_DIR) && cp src/VersionInfo.h.in src/VersionInfo.h
	cd $(PAHO_DIR)/src && \
		$(CC) -c -I. $(if $(filter Darwin,$(shell uname -s)),-DOSX) *.c
	cd $(PAHO_DIR) && ar rcs build/src/libpaho-mqtt3a.a src/*.o

mqtt_client: $(PAHO_LIB) mqtt_client.c
	$(CC) mqtt_client.c -o mqtt_client \
		-I $(PAHO_DIR)/src \
		-L $(PAHO_DIR)/build/src \
		-lpaho-mqtt3a \
		-lpthread $(if $(filter Darwin,$(shell uname -s)),,-lrt)

clean:
	rm -f mqtt_client
	rm -rf $(PAHO_DIR)/build

.PHONY: all clean
